package com.hmy.equipment.controller;

import com.hmy.equipment.domain.HmyFans;
import com.hmy.equipment.service.AeviceState;
import com.hmy.equipment.service.HmyFansService;
import com.ruoyi.common.core.web.constant.TableName;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：kdq
 * @description：气体交换机
 * @date ：2024/1/30 19:12
 */

@RestController
@RequestMapping("/fans")
public class HmyFansController extends BaseController {

    @Resource
    private HmyFansService hmyFansService;
    @Resource
    private AeviceState aeviceState;

    /**
     * * @param null
     *
     * @return
     * @author kdq
     * @date 2024/1/30 19:20
     * @description 气体交换机设备添加
     */
    @RequiresPermissions("equipment:fans:add")
    @Log(title = "气体交换机设备添加", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addHmyFans(@RequestBody HmyFans hmyFans) {
        int i = hmyFansService.addFans(hmyFans);
        //aeviceState.getPhouseCoudInTable(TableName.FANS, hmyFans.getPhouseCode());
        return AjaxResult.success(i);
    }


    /**
     * * @param null
     *
     * @return
     * @author kdq
     * @date 2024/1/30 19:20
     * @description 气体交换机设备修改
     */
    @RequiresPermissions("equipment:fans:edit")
    @Log(title = "气体交换机设备修改", businessType = BusinessType.INSERT)
    @PostMapping("/edit")
    public AjaxResult editHmyFans(@RequestBody HmyFans hmyFans) {
        int i = hmyFansService.editFans(hmyFans);
        aeviceState.getPhouseCoudInTable(TableName.FANS, hmyFans.getPhouseCode());
        return AjaxResult.success(i);
    }


    /**
     * * @param null
     *
     * @return
     * @author kdq
     * @date 2024/1/30 22:32
     * @description 查询所有气体交换机
     */
//    @RequiresPermissions("equipment:fans:list")
    @Log(title = "查询所有气体交换机", businessType = BusinessType.INSERT)
    @GetMapping("/select")
    public TableDataInfo selectAll(String fansType,
                                   String fansBrand,
                                   String phouseCode
    ) {
        startPage();
        List<HmyFans> hmyFansList = hmyFansService.selectAll(fansType, fansBrand, phouseCode);
        return getDataTable(hmyFansList);
    }


    /**
     * * @param null
     *
     * @return
     * @author kdq
     * @date 2024/1/30 22:34
     * @description 根据id删除单个记录
     */
    @RequiresPermissions("equipment:fans:delete")
    @Log(title = "根据id删除记录", businessType = BusinessType.INSERT)
    @DeleteMapping("delete/{fansType}")
    public AjaxResult deleteById(@PathVariable String fansType) {
        String phouseCode = hmyFansService.selectByFansId(fansType).getPhouseCode();
        int i = hmyFansService.deleteById(fansType);
        aeviceState.getPhouseCoudInTable(TableName.FANS, phouseCode);
        return AjaxResult.success(i);
    }


    /**
     * * @param null
     *
     * @return
     * @author kdq
     * @date 2024/1/31 23:09
     * @description 根据id查询气体交换机
     */
    @Log(title = "根据型号查询气体交换机", businessType = BusinessType.INSERT)
    @GetMapping("/selectbyid/{fansType}")
    public AjaxResult selectAll(@PathVariable String fansType) {
        return AjaxResult.success(hmyFansService.selectByFansId(fansType));
    }


}
